<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .App {
            width: 600px;
            height: 400px;
            background-color: pink;
        }

        .One {
            width: 400px;
            height: 200px;
            background-color: skyblue;
        }
    </style>
</head>

<body>
    <div id="root">

    </div>
</body>
<script src="../react.js"></script>
<script src="../react-dom.js"></script>
<!-- 用来将jsx语法转化为js语法 -->
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js"></script>
<script type="text/babel">
    class App extends React.Component {
        state = {
            num: 6
        }
        // 定义函数 设置更新状态
        getNum = (num) => {
            this.setState({ num: num });
        }

        // 渲染 父组件状态    子组件得到父组件num值
        render() {
            return (
                <div className='App'>
                    父组件---{this.state.num}
                    <One onGetNum={this.getNum} />
                </div>
            )
        }
    }

    class One extends React.Component {
        state = {
            num: 5
        }
        render() {
            return (
                // 子组件   点击按钮props接收子组件已经接收到父组件的媒介 
                <div className='One'>
                    子组件---{this.state.num}
                    <button onClick={() => {
                        // onGetNum 父组件传来的
                        this.props.onGetNum(this.state.num)
                    }}>传值</button>
                </div>
            )
        }
    }
    ReactDOM.render(<App />, document.getElementById('root'))
</script>

</html>